home *** CD-ROM | disk | FTP | other *** search
- /*
- ** MakeComment.ced
- **
- ** $VER: MakeComment.ced 1.1 (14.1.95)
- **
- ** This script makes comment boxes like this. It makes provision for various
- ** languages and has two box-styles. These properties are specified by using
- ** parameters.
- ** To comment a block, mark it and call this macro. To comment a line,
- ** just call the macro.
- ** See docs for more details.
- **
- ** This script requires CygnusEd Professional v3.5 (or later) to run.
- **
- ** Copyright © 1993-95 Michael Letowski
- */
-
- /* Get host */
- PARSE SOURCE com res called resolved ext host .
- IF host="REXX" THEN /* From command line */
- ADDRESS "rexx_ced" /* Talk to default ced */
-
- OPTIONS RESULTS /* Hear it from CED */
- ARG commentType language . /* How to comment? */
-
- /* Specify known languages here: */
-
- Len.=2; Beg.="/*"; End.="*/"; Fill.="*" /* Defaults */
- Len.pas=2; Beg.pas="(*"; End.pas="*)"; Fill.pas="*"
- Len.p=2; Beg.p="{*"; End.p="*}"; Fill.p="*"
- Len.cpp=2; Beg.cpp="//"; End.cpp="//"; Fill.cpp="/"
- Len.hpp=2; Beg.hpp="//"; End.hpp="//"; Fill.hpp="/"
- Len.ada=2; Beg.ada="--"; End.ada="--"; Fill.ada="-"
- Len.bas=1; Beg.bas="'"; End.bas="'"; Fill.bas="'"
- Len.asm=1; Beg.asm="*"; End.asm="*"; Fill.asm="*"
- Len.s=1; Beg.s=";"; End.s=";"; Fill.s= ";"
- Len.mak=1; Beg.mak="#"; End.mak="#"; Fill.mak= "#"
-
- LF="0A"X
- TAB="09"X
- Ops=0 /* Number of ops for undo */
-
- IF language="" THEN /* Language not explicitly given */
- DO
- 'Status RESTNAME' /* Get file name */
- PARSE UPPER VAR RESULT 1 "." language
- END
-
- 'Status RIGHTBORDER' /* Get right border value */
- Border=RESULT /* And store it */
-
- 'DM "Commenting..."'
-
- 'Cut block' /* Cut marked block */
- IF RESULT THEN /* There is a marked block */
- CALL CommentBlock /* Comment as block */
- ELSE /* No marked block */
- CALL CommentLine /* Comment as line */
-
- CALL SetClip(UndoClipName(),Ops) /* Set data for Undo.ced */
-
- 'DM' /* Restore status line */
-
- EXIT /* Finished */
-
- CommentBlock:
- 'Status BLOCKBUFFER' /* Get buffer */
- ToComment=RESULT /* And store it */
- IF Length(ToComment)=0 THEN /* Nothing to comment */
- DO
- 'Okay1' "No area marked."
- RETURN
- END
- Ops=Ops+1
- Lines=Length(ToComment)-Length(Compress(ToComment,LF))
- /* Get number of lines in buffer */
- IF Lines=0 THEN /* This is part of a line */
- DO
- ToComment=ToComment||LF /* Change it to line */
- Lines=1
- END
- ToInsert="" /* Initialize block */
- DO FOR Lines /* For each line... */
- LFPos=Pos(LF,ToComment) /* Find end of a line */
- CurrLine=SubStr(ToComment,1,LFPos-1)
- /* Cut the line */
- ToComment=DelStr(ToComment,1,LFPos)
- /* And remove it from block */
- ToInsert=ToInsert||MakeLine(CurrLine)
- /* Append comments */
- END
- 'Text' MakeFirstLine()||ToInsert||MakeLastLine()
- /* Insert back to CED */
- Ops=Ops+RESULT
- RETURN
-
- CommentLine:
- 'Delete Line' /* Delete current line */
- Ops=Ops+RESULT
- 'Status DELETELINEBUFFER' /* Get it line */
- ToComment=Compress(RESULT,LF) /* And save it without LFs */
- 'Text' MakeFirstLine()||MakeLine(ToComment)||MakeLastLine()
- /* Insert to CED */
- Ops=Ops+RESULT
- RETURN
-
- MakeLine:
- PARSE ARG cL
- SELECT
- WHEN Abbrev("SHORT",Upper(commentType)) THEN
- cL=Copies(Fill.language,Len.language)||TAB||cL||LF
- WHEN Abbrev("LONG",Upper(commentType)) THEN
- DO
- cL=Translate(cL," ",TAB) /* Change tabs to spaces */
- IF Length(cL)<=Border-2*Len.language THEN
- /* Line short enough */
- cL=CENTER(cl,Border-2*Len.language)
- /* Center line */
- cL=Beg.language||cL||End.language||LF
- END
- OTHERWISE
- cL=Copies(Fill.language,Len.language)||TAB||cL||LF
- END
- RETURN cL
-
- MakeFirstLine:
- SELECT
- WHEN Abbrev("SHORT",Upper(commentType)) THEN /* Short comment */
- cL=Beg.language||LF
- WHEN Abbrev("LONG",Upper(commentType)) THEN /* Full line comment */
- cL=Beg.language||Copies(Fill.language,Border-4)||End.language||LF
- OTHERWISE
- cL=Beg.language||LF
- END
- RETURN cL
-
- MakeLastLine:
- SELECT
- WHEN Abbrev("SHORT",Upper(commentType)) THEN
- cL=End.language||LF
- WHEN Abbrev("LONG",Upper(commentType)) THEN
- cL=Beg.language||Copies(Fill.language,Border-4)||End.language||LF
- OTHERWISE
- cL=End.language||LF
- END
- RETURN cL
-
- Extension:
- PARSE ARG name "." ext
- RETURN ext
-
- UndoClipName:
- 'Status FILEMEM' /* Get address of current file */
- RETURN "CEDUndo."Right(D2X(RESULT),8,"0") /* Prepare unique name */
-